<%--
  Created by IntelliJ IDEA.
  User: d6416
  Date: 2018/12/1
  Time: 12:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    String _id=request.getParameter("_");
%>

<form id="form_user_account" class="form-horizontal">
    <input type="hidden" id="userId" name="userId" value="${user.id}"/>
    <input type="hidden" id="adminId" name="adminId" value="${admin.id}"/>
    <input type="hidden" id="type" name="type" value="${type}"/>

    <c:if test="${type=='username'}">
        <div class="form-group">
            <label class="col-md-2 control-label">用户名</label>
            <div class="col-md-8">
                <input type="text" class="form-control" id="username" name="username" value="${admin.username}" placeholder="请输入新用户名" />
            </div>
        </div>
    </c:if>

    <c:if test="${type=='userMobile'}">
        <div class="form-group">
            <label class="col-md-2 control-label">手机号</label>
            <div class="col-md-8">
                <input type="text" class="form-control" id="userMobile" name="userMobile" value="${admin.userMobile}" placeholder="请输入新手机号" />
            </div>
        </div>
    </c:if>

    <c:if test="${type=='userEmail'}">
        <div class="form-group">
            <label class="col-md-2 control-label">邮箱</label>
            <div class="col-md-8">
                <input type="text" class="form-control" id="userEmail" name="userEmail" value="${admin.userEmail}" placeholder="请输入新邮箱" />
            </div>
        </div>
    </c:if>

    <c:if test="${type=='userWeiChat'}">
        o(╥﹏╥)o
    </c:if>

</form>

<script>

    $(function(){
        fn_account_input_valid();
    });

    function fn_account_input_valid(){
        __init_validate("form_user_account", {
            rules : {
                username : {
                    required : true,
                    minlength : 2,
                    maxlength : 10,
                    remote : {
                        url : "<%=path%>/main/member/checkAccount",
                        delay : 500,
                        type : "POST",
                        dataType : "json",
                        data : {
                            account : function(){
                                return $("#form_user_account #username").val();
                            }
                        }
                    }
                },
                userMobile : {
                    required : true,
                    checkPhone : true,
                    remote : {
                        url : "<%=path%>/main/member/checkAccount",
                        delay : 500,
                        type : "POST",
                        dataType : "json",
                        data : {
                            account : function(){
                                return $("#form_user_account #userMobile").val();
                            }
                        }
                    }
                },
                userEmail : {
                    required : true,
                    email : true,
                    remote : {
                        url : "<%=path%>/main/member/checkAccount",
                        delay : 500,
                        type : "POST",
                        dataType : "json",
                        data : {
                            account : function(){
                                return $("#form_user_account #userEmail").val();
                            }
                        }
                    }
                }
            },
            messages : {
                username : {
                    required : "请填写新用户名",
                    remote : "已经存在此用户名了"
                },
                userMobile : {
                    required : "请填写新手机号",
                    remote : "已经存在此手机号了"
                },
                userEmail : {
                    required : "请填写新邮箱",
                    remote : "已经存在此邮箱了",
                    email : "请输入正确的邮箱"
                }
            }
        })
    }

    $.validator.addMethod("checkPhone", function(value, element, params){
        var checkPhone = /^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\d{8}$/;
        return this.optional(element) || (checkPhone.test(value));
    },"请输入正确的手机号");

    function fn_member_account_update(callback){
        if($("#form_user_account").valid()){
            __confirm_dialog("提示","确定提交吗",function(){
                __form_save("form_user_account", "<%=path%>/main/member/updateAccount", function(data){
                    callback(data);
                });
            },function(){
                callback();
            })
        }else{
            callback();
        }
    }

</script>